package com.example.bookstore.dao.impl;

import com.example.bookstore.dao.UserDao;
import com.example.bookstore.pojo.User;

import java.sql.SQLException;

public class UserDaoImpl extends BaseDao<User> implements UserDao {

    @Override
    public User queryUserByUsername(String username) throws SQLException {
        String sql = "select `id`,`username`,`password`,`email` from t_user where username = ? ";
        return querySingle(sql, User.class,username);
    }

    @Override
    public int saveUser(User user) throws SQLException {
        String sql = "insert into t_user(`username`,`password`,`email`) values(?,?,?)";
        return update(sql,user.getUsername(),user.getPassword(),user.getEmail());
    }

    @Override
    public User queryUserByUsernameAndPassword(String username, String password) throws SQLException {
        String sql = "select `id`,`username`,`password`,`email` from t_user where username = ? and password = ?";
        return querySingle(sql, User.class,username,password);
    }
}
